package cn.livingCloud.service.impl.operation;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.dto.UserFormDto;
import cn.livingCloud.entity.user.User;
import cn.livingCloud.repository.UserMapper;
import org.apache.commons.lang.StringUtils;

/**
 * Created by 唐旭 on 2015/12/3.
 */
public class UserFormDtoUpdater {

    private UserMapper userMapper = BeanProvider.getBean(UserMapper.class);

    private UserFormDto formDto;

    public UserFormDtoUpdater(UserFormDto formDto) {
        this.formDto = formDto;
    }

    public void update() {
        String uuid = formDto.getUuid();
        User user;
        if (StringUtils.isEmpty(uuid)) {
            user = new User();
            formDto.updateUser(user);
            user.save();
        } else {
            user = userMapper.findUserByUuid(uuid);
            formDto.updateUser(user);
            user.update();
        }
    }
}
